<?php

namespace App\Admin\Controllers;

use App\Dealer;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;
use Encore\Admin\Show;

class WinnersController extends Controller
{
    use HasResourceActions;

    /**
     * Index interface.
     *
     * @param Content $content
     * @return Content
     */
    public function index(Content $content)
    {
        return $content
            ->header('中奖列表')
            ->description('description')
            ->body($this->grid());
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Dealer);
        $grid->model()->where('is_win', '>', 0)->orderBy('is_win', 'asc');
        $grid->filter(function ($filter) {
            // 去掉默认的id过滤器
            $filter->disableIdFilter();
            $filter->like('name', '名字');
            $filter->equal('is_win', '奖项等级')->select([
                1 => '一等奖',
                2 => '二等奖',
                3 => '三等奖'
            ]);
        });
        $grid->disableCreateButton();
        $grid->disableActions();
        $grid->id('Id');
        $grid->name('名字');
        $grid->region('大区');
        $grid->market('区域');
        $grid->company('公司');
        $grid->is_win('奖项')->display(function ($v) {
            $list = [
                1 => '一等奖',
                2 => '二等奖',
                3 => '三等奖'
            ];
            return $list[$v];
        });

        return $grid;
    }

}
